#include "primitives.h"


void drawCilindro(float radius, float height, int divisoes) {
    
    float alpha = 0;
    float beta = 0;
    int i;
    float step = (2*PI)/divisoes;

    glBegin(GL_TRIANGLES);
    
    for(i = 0; i <= divisoes; i++) {
        //desenha base superior
		glColor3f(0.2,0.7, 0.1);
        glVertex3f(0, height*1, 0);
        glVertex3f(radius*sin(alpha),height*1 , radius*cos(beta)); 
        glVertex3f(radius*sin(alpha + step), height*1,radius* cos(beta + step));       
        
        alpha += step;
        beta += step;
    }            
    
    alpha = 0;
    beta = 0;
    
    for(i = 0; i <= divisoes; i++) {
        //desenha base inferior
		glColor3f(0.5, 0.5, 1);
        glVertex3f(radius*sin(alpha), height*-1 , radius*cos(beta));
        glVertex3f(0, -1, 0);
        glVertex3f(radius*sin(alpha + step), height*-1,radius* cos(beta + step));

        
        alpha += step;
        beta += step;
        
    }                
    
    for (i = 0; i <= divisoes; i++) {
		//desenha Corpo
        glColor3f(0.9, 1, 1);
        glVertex3f(radius*sin(alpha), height*1, radius*cos(beta));
        glVertex3f(radius*sin(alpha + step), height*-1,radius* cos(beta + step));
        glVertex3f(radius*sin(alpha + step),height*1,radius* cos(beta + step));
        
        glColor3f(0, 0, 1);
        glVertex3f(radius*sin(alpha), height*1, radius*cos(beta));   
        glVertex3f(radius*sin(alpha), height*-1,radius* cos(beta));
        glVertex3f(radius*sin(alpha + step), height*-1, radius*cos(beta + step));
        
        
        alpha += step;
        beta += step;
        
    }
    
    glEnd();
    
    
}


void drawCilindroBase1(float radius, float height, int divisoes){
	 float alpha = 0;
    float beta = 0;
    int i;
    float step = (2*PI)/divisoes;

    glBegin(GL_TRIANGLES);            
    
    for (i = 0; i <= divisoes; i++) {
		//desenha Corpo
		glColor3f(0.5, 0.5, 1);
			glVertex3f(sin(alpha), 1, cos(beta));
			glVertex3f(sin(alpha + step), -1, cos(beta + step));
			glVertex3f(sin(alpha + step), 1, cos(beta + step));      
			 //parte dentro
				glVertex3f(sin(alpha), 1, -cos(beta));
				glVertex3f(sin(alpha + step), -1, -cos(beta + step));
				glVertex3f(sin(alpha + step), 1, -cos(beta + step));    
		glColor3f(0.5, 0.5, 1);
			glVertex3f(sin(alpha), 1, cos(beta));   
			glVertex3f(sin(alpha), -1, cos(beta));
			glVertex3f(sin(alpha + step), -1, cos(beta + step));   
			 //parte dentro
				glVertex3f(sin(alpha), 1, -cos(beta));   
				glVertex3f(sin(alpha), -1, -cos(beta));
				glVertex3f(sin(alpha + step), -1, -cos(beta + step));  
        alpha += step;
        beta += step;
        
    }
    
    glEnd();
    
}
void drawParalelepipedo(float width, float length, float height) {
    
    width = width/2;
    length = length/2;
    height = height/2;
    
    glBegin(GL_TRIANGLES);
    
    //front face
    glColor3f(1, 0, 0);
    glVertex3d(-width, -height , length);
    glVertex3d(width, -height, length);
    glVertex3d(-width, height, length);
    
    glVertex3d(width, -height, length);
    glVertex3d(width, height, length);
    glVertex3d(-width, height, length);
    
    //right face
    glColor3f(0, 1, 0);
    glVertex3d(width, -height, length);
    glVertex3d(width, -height, -length);
    glVertex3d(width, height, -length);
    
    glVertex3d(width, height, -length);
    glVertex3d(width, height, length);
    glVertex3d(width, -height, length);
    
    //left face
    glColor3f(0, 0, 1);
    glVertex3d(-width, -height, -length);
    glVertex3d(-width, -height, length);
    glVertex3d(-width, height, length);
    
    glVertex3d(-width, height, length);
    glVertex3d(-width, height, -length);
    glVertex3d(-width, -height, -length);
    
    
    //back face
    glColor3f(1, 1, 0);
    glVertex3d(-width, -height , -length);
    glVertex3d(width, height, -length);
    glVertex3d(width, -height, -length);
    
    glVertex3d(-width, -height, -length);
    glVertex3d(-width, height, -length);
    glVertex3d(width, height, -length);
    
    //upper face
    glColor3f(0, 1, 1);
    glVertex3d(-width, height , length);
    glVertex3d(width, height, length);
    glVertex3d(width, height, -length);
    
    glVertex3d(width, height, -length);
    glVertex3d(-width, height, -length);
    glVertex3d(-width, height, length);
    
    
    //lower face
    glColor3f(1, 1, 1);
    glVertex3d(-width, -height , length);
    glVertex3d(width, -height, -length);
    glVertex3d(width, -height, length);
    
    
    glVertex3d(width, -height, -length);
    glVertex3d(-width, -height, length);
    glVertex3d(-width, -height, -length);
    
    glEnd();
    
}
void drawPlano(float x,float y,float z,int orientacao){

	// ORIENTATION : 1 PLANO CIMA, 0 PLANO BAIXO
	   if(orientacao) {
        glBegin(GL_TRIANGLES);
        glVertex3f(-x, y, z);
        glVertex3f(x, y, z);
        glVertex3f(x, y, -z);
        
        glVertex3f(x, y, -z);
        glVertex3f(-x, y, -z);
        glVertex3f(-x, y, z);
                
        glEnd();
        
    }
    else {

        glBegin(GL_TRIANGLES);
        glColor3f(1,y,1);
        glVertex3f(-x, y, z);
        glVertex3f(x, y, -z);
        glVertex3f(x, y, z);
        
        glVertex3f(x, y, -z);
        glVertex3f(-x, y, z);
        glVertex3f(-x, y, -z);   

        glEnd(); 
        
    }


}
void drawEsfera(float radius, int aros, int slices) {


	//stacks sao as linhas da esfera, e slices sao os triangulos que preenchem cada linha 
    float alpha, beta;
    float step_v = 2*PI/slices;
    float step_h = PI/aros;

    glBegin(GL_TRIANGLES);
    for(alpha = 0; alpha < (2*PI); alpha += step_v) {
        for(beta = (-PI/2); beta < (PI/2); beta += step_h) {
             

        glColor3f(1,0,0);
        glVertex3f(radius * cos(beta + step_h) * sin(alpha), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha));
       
        glVertex3f(radius * cos(beta) * sin(alpha), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha));
        
        glVertex3f(radius * cos(beta) * sin(alpha + step_v), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha + step_v));


        glColor3f(1,1,0);
        glVertex3f(radius * cos(beta) * sin(alpha + step_v), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha + step_v));
        
        glVertex3f(radius * cos(beta + step_h) * sin(alpha + step_v), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha + step_v));
        
        glVertex3f(radius * cos(beta + step_h) * sin(alpha), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha));

        }
    }
    glEnd();
}


void drawEsferaMetade(float radius, int aros, int slices) {


	//stacks sao as linhas da esfera, e slices sao os triangulos que preenchem cada linha 
    float alpha, beta;
    float step_v = PI/slices;
    float step_h = PI/aros;

    glBegin(GL_TRIANGLES);
    for(alpha = 0; alpha < (PI); alpha += step_v) {
        for(beta = (-PI/2); beta < (PI); beta += step_h) {
             

        glColor3f(1,0,0);
        glVertex3f(radius * cos(beta + step_h) * sin(alpha), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha));
       
        glVertex3f(radius * cos(beta) * sin(alpha), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha));
        
        glVertex3f(radius * cos(beta) * sin(alpha + step_v), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha + step_v));


        glColor3f(1,1,0);
        glVertex3f(radius * cos(beta) * sin(alpha + step_v), 
            radius * sin(beta), 
            radius * cos(beta) * cos(alpha + step_v));
        
        glVertex3f(radius * cos(beta + step_h) * sin(alpha + step_v), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha + step_v));
        
        glVertex3f(radius * cos(beta + step_h) * sin(alpha), 
            radius * sin(beta + step_h), 
            radius * cos(beta + step_h) * cos(alpha));

        }
    }
    glEnd();
}

void drawcubo(float size){
    
    glBegin(GL_TRIANGLES);
    
    //front face
    glColor3f(1, 0, 0);
    glVertex3d(-size, -size , size);
    glVertex3d(size, -size, size);
    glVertex3d(-size, size, size);
    
    glVertex3d(size, -size, size);
    glVertex3d(size, size, size);
    glVertex3d(-size, size, size);
    
    //right face
    glColor3f(0, 1, 0);
    glVertex3d(size, -size, size);
    glVertex3d(size, -size, -size);
    glVertex3d(size, size, -size);
    
    glVertex3d(size, size, -size);
    glVertex3d(size, size, size);
    glVertex3d(size, -size, size);
    
    //left face
    glColor3f(0, 0, 1);
    glVertex3d(-size, -size, -size);
    glVertex3d(-size, -size, size);
    glVertex3d(-size, size, size);
    
    glVertex3d(-size, size, size);
    glVertex3d(-size, size, -size);
    glVertex3d(-size, -size, -size);
    
    
    //back face
    glColor3f(1, 1, 0);
    glVertex3d(-size, -size , -size);
    glVertex3d(size, size, -size);
    glVertex3d(size, -size, -size);
    
    glVertex3d(-size, -size, -size);
    glVertex3d(-size, size, -size);
    glVertex3d(size, size, -size);
    
    //upper face
    glColor3f(0, 1, 1);
    glVertex3d(-size, size , size);
    glVertex3d(size, size, size);
    glVertex3d(size, size, -size);
    
    glVertex3d(size, size, -size);
    glVertex3d(-size, size, -size);
    glVertex3d(-size, size, size);
    
    
    //lower face
    glColor3f(1, 1, 1);
    glVertex3d(-size, -size , size);
    glVertex3d(size, -size, -size);
    glVertex3d(size, -size, size);

    
    glVertex3d(size, -size, -size);
    glVertex3d(-size, -size, size);
    glVertex3d(-size, -size, -size);
        
    glEnd();
}

